#!/usr/bin/env python


import os
import sys
import shutil

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from runtest_dalton import Filter, TestRun

test = TestRun(__file__, sys.argv)

a = Filter()
a.add(string = 'Final DFT energy',
      rel_tolerance = 1.0e-8)
a.add(string = 'CONTRIBUTION TO HYPVAL',
      abs_tolerance = 1.0e-8)
a.add(string = '@ omega B',
      abs_tolerance = 1.0e-8)

b = Filter()
b.add(string = 'Final DFT energy',
      rel_tolerance = 1.0e-8)
b.add(from_string = 'FREQUENCY INDEPENDENT SECOND ORDER PROPERTIES',
      num_lines = 6,
      rel_tolerance = 1.0e-8)

test.run(['rsp_g_kshfx_dir_1.dal'], ['CH3_STO-3G_sym.mol'], f={'out': a}, args='-get SIRIUS.RST',
         accepted_errors=['functional not fully implemented/tested for QR'])

shutil.move('rsp_g_kshfx_dir_1_CH3_STO-3G_sym.SIRIUS.RST','SIRIUS.RST')

test.run(['rsp_g_kshfx_dir_2.dal'], ['CH3_STO-3G_sym.mol'], f={'out': b}, args='-put SIRIUS.RST -get SIRIUS.RST')

shutil.move('rsp_g_kshfx_dir_2_CH3_STO-3G_sym.SIRIUS.RST','SIRIUS.RST')

test.run(['rsp_g_kshfx_dir_3.dal'], ['CH3_STO-3G_sym.mol'], f={'out': b}, args='-put SIRIUS.RST')

os.remove('SIRIUS.RST')

sys.exit(test.return_code)
